#ifndef COMMAND_H
#define COMMAND_H
//command file
#include "datatype.h"
#include <QString>
class Command
{
public:
    UCHAR frame_header[18];
    unsigned short fun_code;

    UCHAR sn[6];
    //register frame special
    UCHAR product_key[10];
    UCHAR cust_sn[10];
    UCHAR device_sn[10];
    UCHAR imei[19];//part
    UCHAR iccid[24];  //20 byte iccid
    UCHAR sw_version[8];
    UCHAR upgrade_flag[5];
    UCHAR crc_full[6];
    //gps data frame special
    UCHAR station_latitude[16];
    UCHAR station_longitude[16];
    UCHAR gps_latitude[16];
    UCHAR gps_longitude[16];
    UCHAR battery_vol[14];
    UCHAR singal_intensity[8];
    UCHAR running_time[7];
    UCHAR vabirant[5];

    UCHAR rawdata[MAX_BUF_LENGTH];
    UCHAR frame_length;

    UCHAR format_time[12];   //180605105342
    QString mysql_qurey;
    unsigned short crc_code;
    unsigned short config_cod;
    int count=0;
    void resolve_from_rawdata();
    void transform_to_rawdata();
    void register_sync_time();
    static QString raw_data_to_qstring(unsigned char*,int size);
    void return_status();

    void configure_command();

    QString register_frame_insert();
    //fun_code=FUN_RETURN_CONFIGURE
    //write back 2 database
    int finish_configure_database();

    //query database
    // get first query 2 modify
    // then process
    int query_configure_databsee(char* configure_buf);

    //1.upgrade
    //2.bind sn
    //3.set host ip
    //4.set host port
    //5. modify work time
    //6.open gps postion
    //7. set sleep interval
    //8.finish

    void configure_upgrade();
    void configure_bind_sn(const char* configure_buf);
    void configure_set_host_ip(const char* configure_buf);
    void configure_set_host_port(const char* configure_buf);
    void configure_set_work_time(const char* configure_buf);
    void configure_open_gps_position();
    void configure_set_sleep_interval(const char* configure_buf);
    void configure_finish();


    int configure(int count);

    u16 SDI_CRC16(unsigned char *puchMsg, unsigned short usDataLen);
    Command();
};


#endif // COMMAND_H
